local duishui = fk.CreateSkill{
  name = "hanqing__duishui",
}

Fk:loadTranslationTable{
  ["hanqing__duishui"] = "对说",
  [":hanqing__duishui"] = "当你的拼点牌亮出后，若此次拼点牌类型相同，你可以选择一项：1.取消此次拼点并使用其中一张拼点牌；"..
  "2.摸一张牌并令你的拼点牌点数视为K。",

  ["hanqing__duishui_cancel"] = "取消此次拼点，你使用其中一张拼点牌",
  ["hanqing__duishui_add"] = "摸一张牌，你的拼点牌点数视为K",
  ["#hanqing__duishui-use"] = "对说：你可以使用其中一张拼点牌",
}

duishui:addEffect(fk.PindianCardsDisplayed, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(duishui.name) and (player == data.from or data.results[player]) then
      if data.fromCard == nil then return end
      local type = data.fromCard.type
      for _, result in pairs(data.results) do
        if result.toCard then
          if result.toCard.type ~= type then return end
        end
      end
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = { "hanqing__duishui_cancel", "hanqing__duishui_add", "Cancel" },
      skill_name = duishui.name,
    })
    if choice ~= "Cancel" then
      event:setCostData(self, {choice = choice})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    if choice == "hanqing__duishui_cancel" then
      local e = room.logic:getCurrentEvent():findParent(GameEvent.SkillEffect)
      if e then
        room.logic:getCurrentEvent():addExitFunc(function()
          e:shutdown()
        end)
      end
      local cards = {}
      if data.fromCard then
        table.insertIfNeed(cards, data.fromCard:getEffectiveId())
      end
      for _, result in pairs(data.results) do
        if result.toCard then
          table.insertIfNeed(cards, result.toCard:getEffectiveId())
        end
      end
      if #cards > 0 then
        room:askToUseRealCard(player, {
          pattern = cards,
          skill_name = duishui.name,
          prompt = "#hanqing__duishui-use",
          extra_data = {
            bypass_times = true,
            extraUse = true,
            expand_pile = cards,
          }
        })
      end
    else
      player:drawCards(1, duishui.name)
      room:changePindianNumber(data, player, 13, duishui.name)
    end
  end,
})

return duishui
